﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace HYElectricSystemSetting
{
	public partial class EditorDataRow : System.Windows.Forms.Form
	{
		public EditorDataRow(int intOrDouble, string columnsone, string columnsTwo, string columnNameOne, string columnNametwo, List<string> SameList)
		{
			this.InitializeComponent();
			this.lbFirstValue.Text = columnNameOne + ":";
			this.tbFirstValue.Text = columnsone;
			this.colValueOne = columnsone;
			this.str = SameList;
			if (columnsTwo != null && columnsTwo != "")
			{
				this.lbSecondValue.Text = columnNametwo + ":";
				this.tbSecondValue.Text = columnsTwo;
				return;
			}
			this.lbSecondValue.Visible = false;
			this.tbSecondValue.Visible = false;
		}

		private void RenameItems_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private void btnAddRows_Click(object sender, EventArgs e)
		{
			this.ischeck = true;
			if (this.tbFirstValue.Text.Trim() == "")
			{
				MessageBox.Show("名称不能为空！", "盈建科提示！");
				this.ischeck = false;
				return;
			}
			if (Convert.ToDouble(this.tbFirstValue.Text) == Convert.ToDouble(this.colValueOne))
			{
				return;
			}
			using (List<string>.Enumerator enumerator = this.str.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (Convert.ToDouble(enumerator.Current) == Convert.ToDouble(this.tbFirstValue.Text))
					{
						MessageBox.Show("此尺寸已存在！", "盈建科提示！");
						this.ischeck = false;
						break;
					}
				}
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void tbFirstValue_KeyPress(object sender, KeyPressEventArgs e)
		{
			ElectricSystemSettingData.PressIntOrDouble(1, sender, e);
		}

		private void tbSecondValue_KeyPress(object sender, KeyPressEventArgs e)
		{
			ElectricSystemSettingData.PressIntOrDouble(0, sender, e);
		}

		private void tbFirstValue_TextChanged(object sender, EventArgs e)
		{
			string text = this.tbFirstValue.Text;
			if (text.IndexOf('.') != -1)
			{
				this.tbFirstValue.Text = text;
			}
		}

		private void tbSecondValue_TextChanged(object sender, EventArgs e)
		{
			string text = this.tbFirstValue.Text;
			if (text.IndexOf('.') != -1)
			{
				this.tbFirstValue.Text = text;
			}
		}

		private void EditorDataRow_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult == DialogResult.OK && !this.ischeck)
			{
				e.Cancel = true;
			}
		}

		private string colValueOne;

		private bool ischeck = true;

		private List<string> str = new List<string>();
	}
}
